import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/config/app_color.dart';
import 'package:flutter_base/config/app_config.dart';
import 'package:flutter_base/generated/assets.dart';
import 'package:flutter_base/utils/utils_other.dart';
import 'package:flutter_base/widgets/image/auto_image.dart';
import 'package:flutter_base/widgets/image/image_view.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class UtilsWidget {
  static buildParticipantsAndRating(List<String> userAvatars, int userCount) {
    List<Widget> avatars = [];
    List<String> avatarUrls = userAvatars.take(3).toList();

    for (int i = 0; i < avatarUrls.length; i++) {
      avatars.add(
        Positioned(
            left: i * 10.w,
            child: ImageView(
              imageUrl: AppConfig.testImage,
              // imageUrl: avatarUrls[i],
              // width: 16.w,
              radius: 8.w,
              border: Border.all(width: 0.5, color: Colors.white),
            )),
      );
    }
    // GetPlatform
    return Row(
      children: [
        // 参与者头像堆叠
        Visibility(
          visible: avatars.isNotEmpty,
          child: SizedBox(
            height: 16.w,
            width: avatars.length * 20.w - 6.w * (avatars.length - 1),
            // ? 20.w
            // : ((avatars.length - 1) * 6.w + 20.w),
            child: Stack(
              children: avatars,
            ).marginOnly(right: 4.w),
          ),
        ),
        // 参与人数
        Expanded(
            child: Text(
          UtilsOther.formatNumberCard(userCount),
          style: TextStyle(
            fontSize: 12.sp,
            fontWeight: FontWeight.w400,
            color: AppColor.color0C0A09,
            letterSpacing: 0.06,
          ),
        )),
      ],
    );
  }

  static Widget buildPriceAndRating(
      {required int? price, required int? discountPrice, required int? star}) {
    // 获取价格显示文本
    String priceText;
    // String getPriceText() {
    //   int price = price ?? 0;
    // if (discountPrice != null && discountPrice > 0) {
    //   price = discountPrice;
    // }

    if ((discountPrice ?? 0) <= 0) {
      priceText = '免费';
    } else {
      priceText = '¥$discountPrice';
    }
    // }
    String originalPriceText;

    int originalPrice = price ?? 0;
    if (discountPrice != null &&
        discountPrice > 0 &&
        discountPrice < originalPrice) {
      originalPriceText = '¥$originalPrice';
    } else {
      originalPriceText = '';
    }
    // "price": 15,
    // "discount_price": 10,

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        // 价格部分
        Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(
              priceText,
              style: TextStyle(
                fontSize: 16.sp,
                fontWeight: FontWeight.w600,
                color: priceText == '免费'
                    ? AppColor.color42B969
                    : AppColor.colorFF4D00,
              ),
            ),
            if (originalPriceText.isNotEmpty) ...[
              SizedBox(width: 4.w),
              Text(
                originalPriceText,
                style: TextStyle(
                  fontSize: 10.sp,
                  fontWeight: FontWeight.w400,
                  color: AppColor.color0C0A09.withOpacity(0.16),
                  decoration: TextDecoration.lineThrough,
                ),
              ),
            ],
          ],
        ),

        // 评分
        Row(
          children: [
            AutoImage(
              Assets.commonStar,
              width: 14.w,
            ),
            SizedBox(width: 4.w),
            Text(
              (star ?? 0) > 0 ? (star! / 10).toString() : '0.0',
              style: TextStyle(
                fontSize: 12.sp,
                fontWeight: FontWeight.w500,
                color: AppColor.color0C0A09,
              ),
            ),
          ],
        ),
      ],
    );
  }
}
